﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM.HTML
{
    #region Using Statements

    using System;

    #endregion
    
    public class HTMLButtonElement : HTMLControlBase
    {
        #region Constructors

        internal HTMLButtonElement(Document owner)
            : base(owner, HTMLConstants.HTML_TAG_BUTTON)
        {
        }

        #endregion

        #region DOM Level 2 HTML Compliance

        /// <summary>
        /// The type of button (all lower case). See the type attribute 
        /// definition in HTML 4.01.
        /// </summary>
        public string type
        {
            get
            {
                String testVal = getAttribute(HTMLConstants.HTML_ATT_TYPE).ToLowerInvariant();

                if (testVal.Equals(HTMLConstants.HTML_BUTTON_SUBMIT) || 
                    testVal.Equals(HTMLConstants.HTML_BUTTON_RESET) || 
                    testVal.Equals(HTMLConstants.HTML_BUTTON_IMAGE))
                {
                    return testVal;
                }
                return HTMLConstants.HTML_BUTTON_SUBMIT;
            }
            set
            {
                String testVal = value.ToLowerInvariant();

                if (testVal.Equals(HTMLConstants.HTML_BUTTON_SUBMIT) || 
                    testVal.Equals(HTMLConstants.HTML_BUTTON_RESET) || 
                    testVal.Equals(HTMLConstants.HTML_BUTTON_IMAGE))
                {
                    setAttribute(HTMLConstants.HTML_ATT_TYPE, testVal);
                }
            }
        }

        #endregion
    }
}
